package net.wenku8.reader.service

import android.util.Log
import net.wenku8.reader.api.UserApi
import net.wenku8.reader.state.StateLogin
import java.util.Timer
import kotlin.concurrent.timer

class SessionKeepService {

    companion object {
        private var keepTimer : Timer? = null
        fun start(){
            if (keepTimer != null){
                return
            }
            keepTimer = timer(period = 10*60*1000) {
                // 执行你的周期性任务
                Log.i("SessionKeepService", "login")
                if (StateLogin.status.value){
                    UserApi.login(StateLogin.username.value, StateLogin.password.value)
                }
            }
        }

        fun stop(){
            keepTimer?.cancel()
            keepTimer = null
        }
    }

}